
export const arrayToObject = (arr, keyProp, valueProp) => {
    let res = {};

    (arr || []).forEach(item => {
        if (Object.hasOwnProperty.call(item, keyProp)) {
            res[item[keyProp]] = valueProp ? (item[valueProp] || '') : item
        }
    })

    return res
}

export const keyToArray = (obj, keyArr) => {
    return (keyArr || []).map(k => obj[k])
}

export const moveToNewIndex = (list, oldIndex, newIndex) => {
    if(oldIndex > newIndex){
        return [
            ...(list.slice(0, newIndex)),
            list[oldIndex],
            ...(list.slice(newIndex, oldIndex)),
            ...(list.slice(oldIndex + 1))
        ]
    } else {
        return [
            ...(list.slice(0, oldIndex)),
            ...(list.slice(oldIndex + 1, newIndex + 1)),
            list[oldIndex],
            ...(list.slice(newIndex + 1))
        ]
    }
}